﻿using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsApp1.Common;

namespace WinFormsApp1.WangHaoQi._02Winfroms
{
    public partial class ScratchesAdd : Form
    {
        public ScratchesAdd()
        {
            InitializeComponent();
            GetMake();
            GetProduction();
        }


        //制单人
        public async void GetMake()
        {
            var items = await HttpClientHelper.RequestUrl<string, ApiResult<List<Makes>>>(URLCommon.Url2, "/WeekListOne_Leo/GetMake", HttpClientHelper.MethodType.GET, default);

            uiComboBox2.DataSource = items.Data;
            uiComboBox2.DisplayMember = "MakeName";
            uiComboBox2.ValueMember = "MakeId";

            this.Controls.Add(uiComboBox2);
        }

        public class Makes
        {
            public int MakeId { get; set; }
            /// <summary>
            /// 制单人名称
            /// </summary>
            public string MakeName { get; set; }
        }

        //班组
        public async void GetProduction()
        {
            var items = await HttpClientHelper.RequestUrl<string, ApiResult<List<Productions>>>(URLCommon.Url2, "/WeekListOne_Leo/GetProduction", HttpClientHelper.MethodType.GET, default);

            uiComboBox1.DataSource = items.Data;
            uiComboBox1.DisplayMember = "ProductionName";
            uiComboBox1.ValueMember = "ProductionId";

            this.Controls.Add(uiComboBox1);
        }

        public class Productions
        {
            public int ProductionId { get; set; }

            /// <summary>
            /// 生产班组名称
            /// </summary>
            public string ProductionName { get; set; }
        }

        public record Scratchetes(DateTime ScratchesDate, string ScratchesDocument, string ScratchesSummary, string ScratchesSlaughter, int ProductionId,bool ScratchesState,
          string ScratchesReviewers, DateTime ScratchesTime, int MakeId,DateTime MakeTime,DateTime MakeUpdateTime , bool IsDelete);

        private async void uiButton1_Click(object sender, EventArgs e)
        {
            var ScratchesDate = Convert.ToDateTime(uiDatePicker1.Text);
            var ScratchesDocument = uiTextBox1.Text;
            var ScratchesSummary = uiTextBox2.Text;
            var ScratchesSlaughter = uiTextBox3.Text; 
            var ProductionId = Convert.ToInt32(uiComboBox1.SelectedValue);
            var ScratchesState = false;
            var ScratchesReviewers = uiTextBox5.Text;
            var ScratchesTime = Convert.ToDateTime(uiDatePicker2.Text);
            var MakeId = Convert.ToInt32(uiComboBox2.SelectedValue);
            var MakeTime = Convert.ToDateTime(uiDatePicker3.Text);
            var MakeUpdateTime = Convert.ToDateTime(uiDatePicker4.Text);
            var IsDelete = false;



            Scratchetes clients = new(ScratchesDate, ScratchesDocument, ScratchesSummary, ScratchesSlaughter, ProductionId, ScratchesState, ScratchesReviewers, ScratchesTime, MakeId, MakeTime, MakeUpdateTime, IsDelete);
            var res = await HttpClientHelper.RequestUrl<Scratchetes, ApiResult<Scratchess>>(URLCommon.Url1, "/WorkList01_leo/GetScratchesAdd", HttpClientHelper.MethodType.POST, clients);
            if (res.Code == 1)
            {
                MessageBox.Show("添加成功");
            }


        }

        public class Scratchess
        {
            public int ScratchesId { get; set; }

            /// <summary>
            /// 单据日期
            /// </summary>
            public DateTime ScratchesDate { get; set; }

            /// <summary>
            /// 单据号
            /// </summary>
            public string ScratchesDocument { get; set; }

            /// <summary>
            /// 生产摘要
            /// </summary>
            public string ScratchesSummary { get; set; }

            /// <summary>
            /// 屠宰计划
            /// </summary>
            public string ScratchesSlaughter { get; set; }

            /// <summary>
            /// 生产班组
            /// </summary>
            public int ProductionId { get; set; }

            /// <summary>
            /// 审核状态
            /// </summary>
            public bool ScratchesState { get; set; }=false;

            /// <summary>
            /// 审核人
            /// </summary>
            public string ScratchesReviewers { get; set; }

            /// <summary>
            /// 审核时间
            /// </summary>
            public DateTime ScratchesTime { get; set; }

            /// <summary>
            /// 制单人
            /// </summary>
            public int MakeId { get; set; }

            /// <summary>
            /// 制单时间
            /// </summary>
            public DateTime MakeTime { get; set; }

            /// <summary>
            /// 最后修改时间
            /// </summary>
            public DateTime MakeUpdateTime { get; set; }


            /// <summary>
            /// 是否删除
            /// </summary>
            public bool IsDeleted { get; set; }
        }
    }
}
